// @Author EthanScriptOn
// @Desc
package dao

import (
	"fmt"
	"gitee.com/fatzeng/srf_switch_dynamic_logic_director/config"
	"gitee.com/fatzeng/srf_switch_dynamic_logic_director/pojo"
)

func InsertUser(userInfo *pojo.SrfSwitchUserInformation) (err error) {
	engine := config.GetMysqlEngine()
	_, err = engine.Insert(&userInfo)
	if err != nil {
		return fmt.Errorf("error inserting data: %v", err)
	}
	return
}

func GetUserInfoByUserId(userId string) (err error, userInfo *pojo.SrfSwitchUserInformation) {
	if userId == "" {
		return fmt.Errorf("userId is empty"), nil
	}
	engine := config.GetMysqlEngine()
	_, err = engine.Id(userId).Get(userInfo)
	if err != nil {
		return fmt.Errorf("error fetching data: %v", err), nil
	}
	return
}

func GetUserInfoByUserName(userName string) (err error, userInfo *pojo.SrfSwitchUserInformation) {
	if userName == "" {
		return fmt.Errorf("UserLogin request is empty"), nil
	}
	engine := config.GetMysqlEngine()
	_, err = engine.Where("Username = ? ", userName).Get(userInfo)
	if err != nil {
		return fmt.Errorf("error fetching data: %v", err), nil
	}
	return
}
